import Route from "./route.js"
import Helper from "./helper.js"
const auth = {};

const key = 'token';

auth.getToken = () => {
	return uni.getStorageSync(key) || '';
}
auth.clearToken = () => {
	uni.clearStorageSync();
}

auth.handleLogin = (data) => {
	uni.setStorageSync(key, data.token);
	uni.setStorageSync('refresh_token', data.refresh_token);
	if (data.info) {
		auth.setInfo(data.info);
	}
}

auth.logout = _ => {
	uni.clearStorageSync();
	Route.to('login');
}

auth.setInfo = info => {
	return uni.setStorageSync('info_66', info);
}

auth.setStoreId = id => {
	return uni.setStorageSync('store_id', id);
}

auth.setOpenid = id => {
	return uni.setStorageSync('openid', id);
}

auth.getStoreId = () => {
	return uni.getStorageSync('store_id');
}

auth.getOpenid = () => {
	return uni.getStorageSync('openid');
}

auth.getInfo = () => {
	return uni.getStorageSync('info_66') || null;
}

auth.getRefresh = () => {
	return uni.getStorageSync('refresh_token') || '';
}

auth.hasLogin = () => {
	let token = uni.getStorageSync(key) || '';
	console.log(token, '登录token');
	return token.length > 0;
}



export default auth;
